package com.efounder.message.struct;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;


public class IMStruct004 extends IMStructAdpter
{
	private byte[] body = new byte[0];

	public void setBody(byte[] body)
	{
		this.body = body;
	}
	public void setBody(String vsbody)
	{
		if(vsbody!=null)
		{
			try
			{
				this.body =vsbody.getBytes("utf-8");
			} catch (UnsupportedEncodingException e)
			{
				e.printStackTrace();
			}
		}
	}

	public byte[] getBody()
	{
		return this.body;
	}
	public byte getMessageType()
	{
		return (byte)4;
	}

	public byte[] toByteArray()
	{
		byte[] byteArray = new byte[1+4+body.length];
		ByteBuffer buffer = ByteBuffer.wrap(byteArray);

		buffer.put(this.getMessageType());
		buffer.putInt(body.length);
		buffer.put(body);

		return byteArray;

	}


	public IMStruct copy()
	{
		IMStruct004 struct = new IMStruct004();
		struct.body = this.body;
		return struct;
	}
}
